package Util::CategoryStore::CategoryStore;
use Moose;
use namespace::autoclean;

has 'schema' => (
	is => 'rw',
	required => 1,
	isa => 'DBIx::Class::Schema',
);

sub get_top_ten {
	my ($self) = @_;
	return $self->schema->resultset('StoresCategory')->search(
                {},
                {
                        select => [
                                'category_id',
				'category.name',
                                {count => 'stores_id', -as=> 'store_count'}
                        ],
			as => [qw/
			category_id	
			category_name	
			store_count	
			/],
                        group_by => [qw/category_id/],
                        join=> 'category',
                        order_by => {-desc => [qw/store_count/]}
                }
        )->slice(0, 9);
}

__PACKAGE__->meta->make_immutable;

1;
